﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;


namespace BAL
{
   public class Industry
    {
        public static string con = BAL.conn.connectionString;

        public static int InsertTempIndustry(int IDUser, string IndustryName, string desc)
        {
            SqlParameter[] arrParam = new SqlParameter[3];
            arrParam[0] = new SqlParameter("@IDUser", SqlDbType.Int);
            arrParam[0].Value = IDUser;
            arrParam[1] = new SqlParameter("@IndusName", SqlDbType.VarChar);
            arrParam[1].Value = IndustryName;
            arrParam[2] = new SqlParameter("@Description", SqlDbType.VarChar);
            arrParam[2].Value =desc;

         int IDTempIndustry=Convert.ToInt32(VocationSpace.DAL.SqlHelper.ExecuteNonQuery(con, CommandType.StoredProcedure, "VS_InsertTempIndustry", arrParam));
         return IDTempIndustry;
            
        }

        public static void PopulateIndustry(ref DropDownList ddlIndustry)
        {
            SqlParameter[] arrParam = new SqlParameter[1];
            arrParam[0] = new SqlParameter("@strSearch", SqlDbType.VarChar);
            arrParam[0].Value = "";
            DataSet ds = VocationSpace.DAL.SqlHelper.ExecuteDataset(con, "VS_GetAllIndustry", arrParam);
            if (ds.Tables.Count > 0)
            {
                if (ds.Tables[0].Rows.Count > 0)
                {
                    ddlIndustry.DataSource = ds.Tables[0];

                    ddlIndustry.DataTextField = "IndustryName";
                    ddlIndustry.DataValueField = "IDIndustry";
                    ddlIndustry.DataBind();

                    ListItem lst = new ListItem("---Select Industry---", "0");
                    ddlIndustry.Items.Insert(0, lst);

                    foreach (ListItem _listItem in ddlIndustry.Items)
                    {

                        _listItem.Attributes.Add("title", _listItem.Text + _listItem.Value);

                    }

                }
                else
                {
                    ddlIndustry.Items.Clear();
                    ListItem lst = new ListItem("---Select Industry---", "0");
                    ddlIndustry.Items.Insert(0, lst);
                }
            }
        }
     

        public static void PopulateContinent(ref DropDownList ddlContinent)
        {
            DataSet ds = VocationSpace.DAL.SqlHelper.ExecuteDataset(con, "VS_GetAllContinent");
            if (ds.Tables.Count > 0)
            {
                if (ds.Tables[0].Rows.Count > 0)
                {
                    ddlContinent.DataSource = ds.Tables[0];

                    ddlContinent.DataTextField = "Continent";
                    ddlContinent.DataValueField = "IDContinent";
                    ddlContinent.DataBind();

                    ListItem lst = new ListItem("---Select Continent---", "-1");
                    ddlContinent.Items.Insert(0, lst);

                    foreach (ListItem _listItem in ddlContinent.Items)
                    {

                        _listItem.Attributes.Add("title", _listItem.Text + _listItem.Value);

                    }

                }
                else
                {
                    ddlContinent.Items.Clear();
                    ListItem lst = new ListItem("---Select Continent---", "-1");
                    ddlContinent.Items.Insert(0, lst);
                }
            }
        }

        public static void PopulateCountry(ref DropDownList ddlCountry)
        {
            DataSet ds = VocationSpace.DAL.SqlHelper.ExecuteDataset(con, "VS_GetAllCountry");
            if (ds.Tables.Count > 0)
            {
                if (ds.Tables[0].Rows.Count > 0)
                {
                    ddlCountry.DataSource = ds.Tables[0];
                    ddlCountry.DataTextField = "CountryName";
                    ddlCountry.DataValueField = "IDCountry";
                    ddlCountry.DataBind();

                    ListItem lst = new ListItem("---Select Country---", "-1");
                    ddlCountry.Items.Insert(0, lst);

                    foreach (ListItem _listItem in ddlCountry.Items)
                    {

                        _listItem.Attributes.Add("title", _listItem.Text + _listItem.Value);

                    }

                }
                else
                {
                    ddlCountry.Items.Clear();
                    ListItem lst = new ListItem("---Select Country---", "-1");
                    ddlCountry.Items.Insert(0, lst);
                }
            }
        }


        public static string  InsertCountry(string CountryName, int IDContinent)
        {
            SqlParameter[] arrParam = new SqlParameter[2];
            arrParam[0] = new SqlParameter("@CountryName", SqlDbType.VarChar);
            arrParam[0].Value = CountryName;
            arrParam[1] = new SqlParameter("@IDContinent", SqlDbType.Int);
            arrParam[1].Value = IDContinent;

          string val=Convert.ToString(VocationSpace.DAL.SqlHelper.ExecuteScalar(con, CommandType.StoredProcedure, "VS_InsertCountry ", arrParam));
          return val;
        }
        public static DataSet GetAllIndustry(string strSearch)
        {
            SqlParameter[] arrParam = new SqlParameter[1];
            arrParam[0] = new SqlParameter("@strSearch", SqlDbType.VarChar);
            arrParam[0].Value = strSearch;
            DataSet ds = VocationSpace.DAL.SqlHelper.ExecuteDataset(con, CommandType.StoredProcedure, "VS_GetAllIndustry", arrParam);
            return ds;
        }

        public static DataSet GetAllVocation()
        {
            SqlParameter[] arrParam = new SqlParameter[1];
            arrParam[0] = new SqlParameter("@strSearch", SqlDbType.VarChar);
            arrParam[0].Value = "";
            DataSet ds = VocationSpace.DAL.SqlHelper.ExecuteDataset(con, CommandType.StoredProcedure, "VS_GetAllVocation", arrParam);
            return ds;
        }

        public static DataSet GetUserByTempIndustry(int IDTempIndustry)
        {
            SqlParameter[] arrParam = new SqlParameter[1];
            arrParam[0] = new SqlParameter("@IDTempIndustry", SqlDbType.Int);
            arrParam[0].Value = IDTempIndustry;
            DataSet ds = VocationSpace.DAL.SqlHelper.ExecuteDataset(con, CommandType.StoredProcedure, "VS_GetUserByTempIndustry", arrParam);
            return ds;
        }

        public static DataSet GetAllTempIndustry()     
        {            
            DataSet ds = VocationSpace.DAL.SqlHelper.ExecuteDataset(con, CommandType.StoredProcedure, "VS_GetAllTempIndustry");
            return ds;
        }

        public static void ApproveTempIndustry(bool IsApprove, string Reason, int IDTempIndustry)
        {
            SqlParameter[] arrParam = new SqlParameter[3];
            arrParam[0] = new SqlParameter("@IsApprove", SqlDbType.Bit);
            arrParam[0].Value = IsApprove;
            arrParam[1] = new SqlParameter("@Reason", SqlDbType.VarChar);
            arrParam[1].Value = Reason;
            arrParam[2] = new SqlParameter("@IDTempIndustry", SqlDbType.Int);
            arrParam[2].Value = IDTempIndustry;


            VocationSpace.DAL.SqlHelper.ExecuteNonQuery(con, CommandType.StoredProcedure, "VS_ApproveTempIndustry", arrParam);

        }
       
    }
}
